package com.wawayaya.util;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;

/**
 * Created by david on 15/11/23.
 */
public class NetUtils {

    public static boolean checkNetworkConnected(Context ct) {
        ConnectivityManager con=(ConnectivityManager)ct.getSystemService(Activity.CONNECTIVITY_SERVICE);
        boolean wifi = false;
        if(con.getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null) {
            wifi=con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
        }
        boolean internet = false;
        if(con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null) {
            internet=con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
        }
        return wifi|internet;
    }

    public static boolean checkNetwork(Context ct) {
        ConnectivityManager con=(ConnectivityManager)ct.getSystemService(Activity.CONNECTIVITY_SERVICE);
        boolean wifi = false;
        if(con.getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null) {
            wifi=con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
        }
        boolean internet = false;
        if(con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null) {
            internet=con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
        }
        return wifi|internet;
    }
}
